<?xml version="1.0" ?>
<!-- 
Gannet OS - Ant Build File

This is the ANT build.xml which controls how the OS is built - it does
everything all the way upto the generation of the OS image file.

This is part of the Gannet OS, For copy right and licensing see LICENSE in the 
root folder, or visit http://gannet.org.uk/license/

-->
<project name="Gannet" default="build_all">
	
	<description>Gannet Build script.</description>
	
	<!-- Comment out the next line if you don't have growl notify -->
	<!-- <property name="growl" location="yes"/> -->
	
	<target name="clean">
		<echo>Wiping the build folder &amp; Recreating</echo>
		<delete dir="build" />
		<mkdir dir="build" />
		<echo>Wiping the isogen folder &amp; Recreating</echo>
		<delete dir="isogen" />
		<mkdir dir="isogen" />
		<echo>Wiping the os image</echo>
		<delete file="gannet.iso" />
	</target>
	
	<target name="sim">
		<echo>Starting simulator (QEMU)</echo>
		<exec executable="qemu-system-i386" dir="." >
			<arg value="-s" />
			<!-- <arg value="-S" /> -->
			
			<arg value="-serial" />
			<arg value="file:qemuout.log" />
			
			<arg value="gannet.iso" />
		</exec>
	</target>
	
	<target name="build_all" depends="clean, build_kernel, build_img, growl_finish">
		<echo>Build Complete</echo>		
	</target>
	
	<target name="growl_finish" if="growl" >
		<exec executable="growlnotify" dir="boot" failonerror='true'>
			<arg value="-m" />
			<arg value="Finished Build" />
			<arg value="-n" />
			<arg value="Gannet Build" />
		</exec>
	</target>
	
	
	<target name="build_img" >
		
		<mkdir dir="isogen/boot" />
		<mkdir dir="isogen/boot/grub" />

		<copy file="grub/grub.cfg" tofile="isogen/boot/grub/grub.cfg" />
		<copy file="build/gannet.bin" tofile="isogen/boot/gannet.bin" />
		
		<exec executable="grub-mkrescue">
			<arg value="-o" />
			<arg value="gannet.iso" />
			<arg value="isogen" />
		</exec>
	</target>
	
	
	
	<target name="build_kernel">
		<echo>Building the kernel entry asm</echo>
		
		<!-- kernel entry first using i586-elf-as -->
		<exec executable="i586-elf-as" dir="kernel" failonerror='true'>
			<arg value="kernel_entry.asm" />
			<arg value="-o" />
			<arg value="../build/kernel_entry.o" />
		</exec>
		
		<!-- kernel.c next -->
		<echo>Compiling Kernel</echo>
		<exec executable="i586-elf-gcc" dir="kernel" failonerror='true'>
			<arg value="-c" />
			<arg value="kernel.c" />

			<arg value="-o" />
			<arg value="../build/kernel.o" />
			
			<arg value="-std=gnu99" />
			<arg value="-ffreestanding" />
			<arg value="-O2" />
			<arg value="-Wall" />
			<arg value="-Wextra" />
		</exec>
		
		<exec executable="i586-elf-gcc" dir="kernel" failonerror='true'>
			<arg value="-c" />
			<arg value="vga.c" />

			<arg value="-o" />
			<arg value="../build/vga.o" />
			
			<arg value="-std=gnu99" />
			<arg value="-ffreestanding" />
			<arg value="-O2" />
			<arg value="-Wall" />
			<arg value="-Wextra" />
		</exec>
		
		<exec executable="i586-elf-gcc" dir="kernel" failonerror='true'>
			<arg value="-c" />
			<arg value="io.c" />

			<arg value="-o" />
			<arg value="../build/io.o" />
			
			<arg value="-std=gnu99" />
			<arg value="-ffreestanding" />
			<arg value="-O2" />
			<arg value="-Wall" />
			<arg value="-Wextra" />
			<arg value="-fgnu89-inline" />
		</exec>
		
		<exec executable="i586-elf-gcc" dir="kernel" failonerror='true'>
			<arg value="-c" />
			<arg value="serial.c" />

			<arg value="-o" />
			<arg value="../build/serial.o" />
			
			<arg value="-std=gnu99" />
			<arg value="-ffreestanding" />
			<arg value="-O2" />
			<arg value="-Wall" />
			<arg value="-Wextra" />

			<arg value="-fgnu89-inline" />
			
		</exec>
		
		<echo></echo>
		<echo></echo>
		<echo>==================================</echo>
		<echo>Linking Kernel and Kernel Launcher</echo>
		<exec executable="i586-elf-gcc" dir="build" failonerror='true'>
			<arg value="-T" />
			<arg value="../kernel/linker.ld" /> <!-- point at kernel/linker.ld -->
			
			<arg value="-o" />
			<arg value="gannet.bin" />
			
			<arg value="-ffreestanding" />
			<arg value="-O2" />
			<arg value="-nostdlib" />

			<arg value="kernel_entry.o" />
			<arg value="kernel.o" />
			<arg value="vga.o" />
			<arg value="io.o" />
			<arg value="serial.o" />
			
			<arg value="-lgcc" />
		</exec>
	</target>
</project>